package com.caac.core.web.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.caac.core.config.Config;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright Intolong 2004</p>
 * <p>Company: Intolong</p>
 * @author <a href="mailto:intolong@163.com">Intolong</a>
 * @version 1.0
 */

public class ConfigListener implements ServletContextListener {
    private static final Log LOG = LogFactory.getLog(ConfigListener.class);
    private static final String CONFIG_LOCATION = "configLocation";
    private static final String WIN_RAR_PATH = "winRarPath";
    private static final String FTP_PATH = "ftpPath";
    private static final String ATTACH_PATH = "attachPath";

    public void contextInitialized(ServletContextEvent event) {
        ServletContext context = event.getServletContext();
        String file = context.getRealPath(context.getInitParameter(
                CONFIG_LOCATION));
        String winRarPath = context.getInitParameter(WIN_RAR_PATH);
        String ftpPath = context.getInitParameter(FTP_PATH);
        String attachPath = context.getInitParameter(ATTACH_PATH);
        try {
            Config.getInstance().config(file, winRarPath, ftpPath, attachPath,
                                        context);
        } catch (Exception e) {
            LOG.error("Error in configing.", e);
        }
    }

    public void contextDestroyed(ServletContextEvent event) {
    }
}
